﻿using System;
using System.Linq;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.IO;
using Foundation;
using BusinessEntity;

namespace GDocsMobile
{
    public partial class FormNew : Form
    {
        public FormNew()
        {
            InitializeComponent();
        }

        private void CreateException(Exception ex)
        {
            MessageBox.Show(ex.Message, "GDocs Mobile Client", MessageBoxButtons.OK, MessageBoxIcon.None, MessageBoxDefaultButton.Button1);
        }

        private void menuItem2_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void menuItem1_Click(object sender, EventArgs e)
        {
            try
            {
                GDocsValidator.ValidateOnNewDoc(txtFilename.Text);

                string lsFilePath = string.Format("{0}{1}.rtf", Constant.GDocsLocalRoot, txtFilename.Text);
                FileStream lStreamWriter = File.Create(lsFilePath);
                lStreamWriter.Write(Properties.Resources.blank, 0, Properties.Resources.blank.Length);
                lStreamWriter.Close();

                System.Diagnostics.Process.Start("pword.exe", "-opendoc " + lsFilePath);

                this.Close();
            }
            catch (Exception ex)
            {
                CreateException(ex);
            }

        }
    }
}